# function_list = []
# poll_lock = threading.Lock()
# notify_fd = -1
# sockets_list = []  # 保存所有活动的socket
# poll_obj=None
# def handle_notify_funcs(tree, text_box):
#         # 添加函数到列表 加锁
#         poll_lock.acquire()
#         for func in function_list:
#             func(tree, text_box)
#         poll_lock.release()
    
# def add_func_to_poll(func):
#     global function_list
#     poll_lock.acquire()
#     function_list.append(func)
#     poll_lock.release()
#     global notify_fd
#     os.write(notify_fd, b'1')


# def add_connection_to_poll(sock):
#     global  sockets_list
#     global poll_obj

#     poll_lock.acquire()
#     poll_obj.register(sock, select.POLLIN)
#     sockets_list.append(sock)
#     poll_lock.release()

# def create_poll_manage_all_conns(tree, text_box):
#         # 初始化poll对象
#     global poll_obj
#     poll_obj = select.poll()
#     global notify_fd
#     notify_fd = os.eventfd(0,  os.EFD_NONBLOCK | os.EFD_CLOEXEC)
#     poll_obj.register(notify_fd, select.POLLIN)
#     global  sockets_list
#     while True:
#         events = poll_obj.poll(1000)
#         for fileno, event in events:
#             if fileno == notify_fd:
#                 while True:
#                     try:
#                         # 读取事件通知
#                         os.read(notify_fd, 8)
#                         handle_notify_funcs(tree, text_box)
#                         break
#                     except OSError:
#                         pass
#             else:    
#                 if event & select.POLLIN:
#                     s = sockets_list[fileno]
#                     data = s.recv(1024)
#                     if not data:
#                         s.close()
#                         sockets_list.remove(s)
#                         poll_obj.unregister(fileno)
#                         tree.set(sock_to_item_id[s], "connStatCol", "disconnected")
#                     else:
#                         # 将接收到的数据添加到文本框中
#                         text_box.insert(tk.END, data.decode('utf-8'))
#                         # 移动滚动条到底部
#                         text_box.see(tk.END)
#                 if event & select.POLLHUP:
#                     s.close()
#                     sockets_list.remove(s)
#                     poll_obj.unregister(fileno)
#                     tree.set(sock_to_item_id[s], "connStatCol", "disconnected")
